package com.demo.event.service;

import com.demo.event.dto.UserLoginEvent02;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.stereotype.Component;

/**
 *
 * @author
 * @since
 */
@Component
@Slf4j
public class UserLoginListenBySmartApplicationListener implements SmartApplicationListener {

  @Override
  public void onApplicationEvent(ApplicationEvent event) {
    log.info("*********** 实现接口 SmartApplicationListener， 接收到 ApplicationEvent 事件************** ");
    log.info("*********** 处理用户登录信息: {}", event);
    log.info("*********** ApplicationEvent 事件处理完毕************** ");
  }


  @Override
  public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
    log.info("supportsEventType执行");
    boolean result = UserLoginEvent02.class == eventType;
    log.info("{} 与类型 {}. 一致:{}", UserLoginEvent02.class.getTypeName(), eventType.getTypeName(), result);
    return result;
  }


  @Override
  public boolean supportsSourceType(Class<?> sourceType) {
    log.info("supportsSourceType 执行");
    boolean result = UserLoginServiceImpl.class == sourceType;
    log.info("{} 与类型 {}. 一致:{}", UserLoginServiceImpl.class.getTypeName(), sourceType.getTypeName(), result);
    return result;
  }


  @Override
  public int getOrder() {
    return 0;
  }


}
